<template>
    <div :class="{ hidden: hidden }" class="pagination">
        <el-pagination
            v-model:current-page="currentPage" v-model:page-size="pageSize" :background="background"
            :layout="layout" :page-sizes="pageSizes" :total="total" @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
        />
    </div>
</template>

<script setup lang="ts">
import { PropType } from 'vue'
import { scrollTo } from '@/utils/scroll-to'
// import paginationData from "@/hooks/paginationData";

const props = defineProps({
    total: {
        required: true,
        type: Number as PropType<number>,
        default: 0
    },
    page: {
        type: Number,
        default: 1
    },
    limit: {
        type: Number,
        default: 20
    },
    pageSizes: {
        type: Array as PropType<number[]>,
        default() {
            return [10, 15, 20, 30, 50]
        }
    },
    layout: {
        type: String,
        default: 'total, sizes, prev, pager, next, jumper'
    },
    background: {
        type: Boolean,
        default: true
    },
    autoScroll: {
        type: Boolean,
        default: true
    },
    hidden: {
        type: Boolean,
        default: false
    }
})
const emit = defineEmits(['pagination', 'update:page', 'update:limit'])
const currentPage = useVModel(props, 'page', emit)
const pageSize = useVModel(props, 'limit', emit)

function handleSizeChange(val: number) {
    emit('pagination', { page: currentPage, limit: val })
    if (props.autoScroll) {
        scrollTo(0, 800)
    }
}

function handleCurrentChange(val: number) {
    currentPage.value = val
    emit('pagination', { page: val, limit: props.limit })
    if (props.autoScroll) {
        scrollTo(0, 800)
    }
}
</script>

<style lang="scss" scoped>
.pagination {
    width: 100%;
    padding: 12px;
    &.hidden {
        display: none;
    }
    :deep(.el-pagination__total) {
        font-size: 14px;
        color: rgb(0 0 0 / 60%);
    }
    :deep(.el-pager li) {
        width: 32px;
        height: 32px;
        background: rgb(255 255 255 / 90%);
        border-radius: 3px;
        border: 1px solid #dcdcdc;
    }
    :deep(.el-pager li.is-active) {
        background: #0052d9;
    }
    :deep(.el-pagination.is-background .btn-prev) {
        width: 40px;
        height: 40px;
        background: transparent;
    }
    :deep(.el-pagination.is-background .btn-prev .el-icon) {
        font-size: 14px;
    }
}
</style>
